<template>
  <div>
    <a-card style="margin-top: 10px" :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="小组名称">
                <a-input placeholder="请输入" v-model="queryParam.groupName" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="小组成员">
                <a-input placeholder="请输入" v-model="queryParam.groupMembersName" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="小组密级">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.groupDense"
                  dictCode="group_intensive_type"
                  placeholder="请选择小组密级"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-button style="margin-bottom: 20px" @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        bordered
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </a-card>
    <ErpContactGroupModal ref="modalForm" @ok="modalFormOk"/>
  </div>
</template>

<script>
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import ErpContactGroupModal from './modules/ErpContactGroupModal.vue'
import { mapGetters } from 'vuex'
import { getAction } from '@/api/manage'

export default {
  name: 'CommonGroupList',
  mixins: [JeecgBpmListMixin],
  components: { ErpContactGroupModal },
  data() {
    return {
      disableMixinCreated: false,
      columns: [
        {
          title: '序号',
          width: 60,
          dataIndex: 'id',
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '小组名称',
          align: 'center',
          width: 180,
          dataIndex: 'groupName',
          ellipsis: true
        },
        {
          title: '小组密级',
          align: 'center',
          dataIndex: 'groupDense_dictText',
          width: 120,
          ellipsis: true
        },
        {
          title: '小组成员',
          align: 'center',
          width: 180,
          dataIndex: 'groupMembersNames',
          ellipsis: true
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          // width: 200,
          ellipsis: true
          // scopedSlots: { customRender: 'remark' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 200,
          scopedSlots: {
            customRender: 'action',
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon'
          }
        }
      ],
      url: {
        list: '/api/erp/publish/erpPublishContactGroup/list',
        delete: '/api/erp/publish/erpPublishContactGroup/delete'
      }
    }
  },
  methods: {
    ...mapGetters(['userInfo']),
    async loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();// 查询条件
      params.groupType = 'public' // 为公用小组的类型
      this.loading = true;
      let res = await getAction(this.url.list, params)
      this.loading = false;
      if (res.success) {
        this.dataSource = res.result ? res.result.records : []
        this.ipagination.total = res.result ? res.result.total : ''
        // 判断是否当前页没有数据且不为第一页
        if (this.dataSource.length == 0 && this.ipagination.current != 1) {
          this.ipagination.current = this.ipagination.current - 1
          this.loadData(this.ipagination.current - 1);
        }

        const data = [...this.dataSource];
        if (this.queryParam.bizTaskType == '1') {
          for (var i = 0; i < data.length; i++) {
            // item.taskUrge = false;
            var item = data[i];
            var params = { flowCode: this.flowCode, dataId: item.id };// 查询条件
            let res2 = await getAction(this.url.checkNotify, params);
            if (res2.result) {
              item.taskUrge = true;
            }
          }
        }
        this.dataSource = data;
      } else {
        this.$message.warning(res.message)
      }
      this.bizCount();
    },
    handleAdd () {
      const params = {
        groupType: 'public'
      }
      this.$refs.modalForm.add(params);
      this.$refs.modalForm.title = '新增';
      this.$refs.modalForm.disableSubmit = false;
    }
  }
}
</script>

<style lang="less" scoped></style>
